package com.lhx.wechat.utils;

import java.security.MessageDigest;

/**
 * 本项目中使用的加密工具
 */
public class CustomerEncryptionUtil {

	public static String md5(String str) {

		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(str.getBytes("utf-8"));
			byte[] digest = md5.digest();
			char[] chars = toHexChars(digest);
			return new String(chars);
		} catch (Exception e) {

		}
		return null;

	}

	private static char[] md5Chars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
			'e', 'f' };

	private static char[] toHexChars(byte[] digest) {
		char[] chars = new char[digest.length * 2];
		int i = 0;
		byte[] var6 = digest;
		int var5 = digest.length;

		for (int var4 = 0; var4 < var5; ++var4) {
			byte b = var6[var4];
			char c0 = md5Chars[(b & 240) >> 4];
			chars[i++] = c0;
			char c1 = md5Chars[b & 15];
			chars[i++] = c1;
		}

		return chars;
	}
}
